package com.ruoyi.project.er.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.er.domain.PaeaErType;
import com.ruoyi.project.er.service.IPaeaErTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 差错类型参数Controller
 *
 * @author ruoyi
 * @date 2020-03-14
 */
@Controller
@RequestMapping("/er/paeaErType")
public class PaeaErTypeController extends BaseController
{
    private String prefix = "er/paeaErType";

    @Autowired
    private IPaeaErTypeService paeaErTypeService;

    @RequiresPermissions("er:paeaErType:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/paeaErType";
    }

    /**
     * 查询差错类型参数列表
     */
    @RequiresPermissions("er:paeaErType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaErType paeaErType)
    {
        startPage();
        List<PaeaErType> list = paeaErTypeService.selectPaeaErTypeList(paeaErType);
        return getDataTable(list);
    }

    /**
     * 导出差错类型参数列表
     */
    @RequiresPermissions("er:paeaErType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaErType paeaErType)
    {
        List<PaeaErType> list = paeaErTypeService.selectPaeaErTypeList(paeaErType);
        ExcelUtil<PaeaErType> util = new ExcelUtil<PaeaErType>(PaeaErType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增差错类型参数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存差错类型参数
     */
    @RequiresPermissions("er:paeaErType:add")
    @Log(title = "差错类型参数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaErType paeaErType)
    {
        paeaErType.setId(paeaErType.getCode());
        return toAjax(paeaErTypeService.insertPaeaErType(paeaErType));
        //return toAjax(paeaErTypeService.saveOrUpdate(paeaErType));
    }

    /**
     * 修改差错类型参数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaErType paeaErType = paeaErTypeService.selectPaeaErTypeById(id);
        mmap.put("paeaErType", paeaErType);
        return prefix + "/edit";
    }

    /**
     * 修改保存差错类型参数
     */
    @RequiresPermissions("er:paeaErType:edit")
    @Log(title = "差错类型参数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaErType paeaErType)
    {
        return toAjax(paeaErTypeService.updatePaeaErType(paeaErType));
        //return toAjax(paeaErTypeService.saveOrUpdate(paeaErType));
    }

    /**
     * 删除差错类型参数
     */
    @RequiresPermissions("er:paeaErType:remove")
    @Log(title = "差错类型参数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaErTypeService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
